
#pragma once
#include <functional>
#include "common.h"

class Channel {
 public:
  DISALLOW_COPY_AND_MOVE(Channel);
  Channel(int fd, EventLoop *loop);
  /**
   * @brief 析构时将 channel 从 epoll 中删除
   */
  ~Channel();


  void HandleEvent() const;
  void EnableRead();
  void EnableWrite();

  int fd() const;
  short listen_events() const;
  short ready_events() const;
  bool exist() const;
  void set_exist(bool in = true);
  void EnableET();

  void set_ready_event(short ev);
  void set_read_callback(std::function<void()> const &callback);
  void set_write_callback(std::function<void()> const &callback);

  static const short READ_EVENT;
  static const short WRITE_EVENT;
  static const short ET;

 private:
  int m_fd;
  EventLoop *m_loop;
  short m_listen_events;
  short m_ready_events;
  bool m_exist;
  std::function<void()> m_read_callback;
  std::function<void()> m_write_callback;
};
